# headache_bc.py

from __future__ import with_statement
import itertools
from pyke import contexts, pattern, bc_rule

pyke_version = '1.1.1'
compiler_version = 1

def migraine(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(itertools.imap(lambda pat, arg:
                              pat.match_pattern(context, context,
                                                arg, arg_context),
                            patterns,
                            arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        with engine.prove(rule.rule_base.root_name, 'score', context,
                          (rule.pattern(0),
                           rule.pattern(1),
                           rule.pattern(2),
                           rule.pattern(3),)) \
          as gen_1:
          for x_1 in gen_1:
            assert x_1 is None, \
              "headache.migraine: got unexpected plan from when clause 1"
            with engine.prove(rule.rule_base.root_name, 'score', context,
                              (rule.pattern(4),
                               rule.pattern(5),
                               rule.pattern(6),
                               rule.pattern(7),)) \
              as gen_2:
              for x_2 in gen_2:
                assert x_2 is None, \
                  "headache.migraine: got unexpected plan from when clause 2"
                with engine.prove(rule.rule_base.root_name, 'score', context,
                                  (rule.pattern(8),
                                   rule.pattern(9),
                                   rule.pattern(2),
                                   rule.pattern(10),)) \
                  as gen_3:
                  for x_3 in gen_3:
                    assert x_3 is None, \
                      "headache.migraine: got unexpected plan from when clause 3"
                    with engine.prove(rule.rule_base.root_name, 'score', context,
                                      (rule.pattern(11),
                                       rule.pattern(12),
                                       rule.pattern(6),
                                       rule.pattern(13),)) \
                      as gen_4:
                      for x_4 in gen_4:
                        assert x_4 is None, \
                          "headache.migraine: got unexpected plan from when clause 4"
                        with engine.prove(rule.rule_base.root_name, 'score', context,
                                          (rule.pattern(14),
                                           rule.pattern(15),
                                           rule.pattern(6),
                                           rule.pattern(16),)) \
                          as gen_5:
                          for x_5 in gen_5:
                            assert x_5 is None, \
                              "headache.migraine: got unexpected plan from when clause 5"
                            mark6 = context.mark(True)
                            if rule.pattern(17).match_data(context, context,
                                    sum_cf(context.lookup_data('ans1'), context.lookup_data('ans2'), context.lookup_data('ans3'), context.lookup_data('ans4'), context.lookup_data('ans5'))):
                              context.end_save_all_undo()
                              rule.rule_base.num_bc_rule_successes += 1
                              yield
                            else: context.end_save_all_undo()
                            context.undo_to_mark(mark6)
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()

def classical_migraine(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(itertools.imap(lambda pat, arg:
                              pat.match_pattern(context, context,
                                                arg, arg_context),
                            patterns,
                            arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        with engine.prove(rule.rule_base.root_name, 'diagnosis', context,
                          (rule.pattern(0),
                           rule.pattern(1),)) \
          as gen_1:
          for x_1 in gen_1:
            assert x_1 is None, \
              "headache.classical_migraine: got unexpected plan from when clause 1"
            with engine.prove('question', 'hd_symptom_aura', context,
                              (rule.pattern(2),)) \
              as gen_2:
              for x_2 in gen_2:
                assert x_2 is None, \
                  "headache.classical_migraine: got unexpected plan from when clause 2"
                rule.rule_base.num_bc_rule_successes += 1
                yield
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()

def opthalmoplegic_migraine(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(itertools.imap(lambda pat, arg:
                              pat.match_pattern(context, context,
                                                arg, arg_context),
                            patterns,
                            arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        with engine.prove(rule.rule_base.root_name, 'diagnosis', context,
                          (rule.pattern(0),
                           rule.pattern(1),)) \
          as gen_1:
          for x_1 in gen_1:
            assert x_1 is None, \
              "headache.opthalmoplegic_migraine: got unexpected plan from when clause 1"
            with engine.prove('question', 'hd_sign_cns', context,
                              (rule.pattern(2),)) \
              as gen_2:
              for x_2 in gen_2:
                assert x_2 is None, \
                  "headache.opthalmoplegic_migraine: got unexpected plan from when clause 2"
                rule.rule_base.num_bc_rule_successes += 1
                yield
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()

def hemiplegic_migraine(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(itertools.imap(lambda pat, arg:
                              pat.match_pattern(context, context,
                                                arg, arg_context),
                            patterns,
                            arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        with engine.prove(rule.rule_base.root_name, 'diagnosis', context,
                          (rule.pattern(0),
                           rule.pattern(1),)) \
          as gen_1:
          for x_1 in gen_1:
            assert x_1 is None, \
              "headache.hemiplegic_migraine: got unexpected plan from when clause 1"
            with engine.prove('question', 'hd_sign_cns', context,
                              (rule.pattern(2),)) \
              as gen_2:
              for x_2 in gen_2:
                assert x_2 is None, \
                  "headache.hemiplegic_migraine: got unexpected plan from when clause 2"
                rule.rule_base.num_bc_rule_successes += 1
                yield
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()

def basilar_migraine_1(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(itertools.imap(lambda pat, arg:
                              pat.match_pattern(context, context,
                                                arg, arg_context),
                            patterns,
                            arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        with engine.prove(rule.rule_base.root_name, 'diagnosis', context,
                          (rule.pattern(0),
                           rule.pattern(1),)) \
          as gen_1:
          for x_1 in gen_1:
            assert x_1 is None, \
              "headache.basilar_migraine_1: got unexpected plan from when clause 1"
            with engine.prove('question', 'vertigo', context,
                              (rule.pattern(2),)) \
              as gen_2:
              for x_2 in gen_2:
                assert x_2 is None, \
                  "headache.basilar_migraine_1: got unexpected plan from when clause 2"
                rule.rule_base.num_bc_rule_successes += 1
                yield
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()

def basilar_migraine_2(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(itertools.imap(lambda pat, arg:
                              pat.match_pattern(context, context,
                                                arg, arg_context),
                            patterns,
                            arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        with engine.prove(rule.rule_base.root_name, 'diagnosis', context,
                          (rule.pattern(0),
                           rule.pattern(1),)) \
          as gen_1:
          for x_1 in gen_1:
            assert x_1 is None, \
              "headache.basilar_migraine_2: got unexpected plan from when clause 1"
            with engine.prove('question', 'ataxia', context,
                              (rule.pattern(2),)) \
              as gen_2:
              for x_2 in gen_2:
                assert x_2 is None, \
                  "headache.basilar_migraine_2: got unexpected plan from when clause 2"
                rule.rule_base.num_bc_rule_successes += 1
                yield
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()

def cluster_headache_1(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(itertools.imap(lambda pat, arg:
                              pat.match_pattern(context, context,
                                                arg, arg_context),
                            patterns,
                            arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        with engine.prove(rule.rule_base.root_name, 'score', context,
                          (rule.pattern(0),
                           rule.pattern(1),
                           rule.pattern(2),
                           rule.pattern(3),)) \
          as gen_1:
          for x_1 in gen_1:
            assert x_1 is None, \
              "headache.cluster_headache_1: got unexpected plan from when clause 1"
            with engine.prove(rule.rule_base.root_name, 'score', context,
                              (rule.pattern(4),
                               rule.pattern(5),
                               rule.pattern(2),
                               rule.pattern(6),)) \
              as gen_2:
              for x_2 in gen_2:
                assert x_2 is None, \
                  "headache.cluster_headache_1: got unexpected plan from when clause 2"
                with engine.prove(rule.rule_base.root_name, 'score', context,
                                  (rule.pattern(7),
                                   rule.pattern(8),
                                   rule.pattern(2),
                                   rule.pattern(9),)) \
                  as gen_3:
                  for x_3 in gen_3:
                    assert x_3 is None, \
                      "headache.cluster_headache_1: got unexpected plan from when clause 3"
                    with engine.prove(rule.rule_base.root_name, 'score', context,
                                      (rule.pattern(10),
                                       rule.pattern(11),
                                       rule.pattern(12),
                                       rule.pattern(13),)) \
                      as gen_4:
                      for x_4 in gen_4:
                        assert x_4 is None, \
                          "headache.cluster_headache_1: got unexpected plan from when clause 4"
                        with engine.prove(rule.rule_base.root_name, 'score', context,
                                          (rule.pattern(14),
                                           rule.pattern(15),
                                           rule.pattern(16),
                                           rule.pattern(17),)) \
                          as gen_5:
                          for x_5 in gen_5:
                            assert x_5 is None, \
                              "headache.cluster_headache_1: got unexpected plan from when clause 5"
                            mark6 = context.mark(True)
                            if rule.pattern(18).match_data(context, context,
                                    sum_cf(context.lookup_data('ans1'), context.lookup_data('ans2'), context.lookup_data('ans3'), context.lookup_data('ans4'), context.lookup_data('ans5'))):
                              context.end_save_all_undo()
                              rule.rule_base.num_bc_rule_successes += 1
                              yield
                            else: context.end_save_all_undo()
                            context.undo_to_mark(mark6)
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()

def tension_headache(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(itertools.imap(lambda pat, arg:
                              pat.match_pattern(context, context,
                                                arg, arg_context),
                            patterns,
                            arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        with engine.prove(rule.rule_base.root_name, 'score', context,
                          (rule.pattern(0),
                           rule.pattern(1),
                           rule.pattern(2),
                           rule.pattern(3),)) \
          as gen_1:
          for x_1 in gen_1:
            assert x_1 is None, \
              "headache.tension_headache: got unexpected plan from when clause 1"
            with engine.prove(rule.rule_base.root_name, 'score', context,
                              (rule.pattern(4),
                               rule.pattern(5),
                               rule.pattern(6),
                               rule.pattern(7),)) \
              as gen_2:
              for x_2 in gen_2:
                assert x_2 is None, \
                  "headache.tension_headache: got unexpected plan from when clause 2"
                mark3 = context.mark(True)
                if rule.pattern(8).match_data(context, context,
                        sum_cf(context.lookup_data('ans1'), context.lookup_data('ans2'))):
                  context.end_save_all_undo()
                  rule.rule_base.num_bc_rule_successes += 1
                  yield
                else: context.end_save_all_undo()
                context.undo_to_mark(mark3)
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()

def depression_headache(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(itertools.imap(lambda pat, arg:
                              pat.match_pattern(context, context,
                                                arg, arg_context),
                            patterns,
                            arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        with engine.prove('question', 'hd_symptom_diurnal', context,
                          (rule.pattern(0),)) \
          as gen_1:
          for x_1 in gen_1:
            assert x_1 is None, \
              "headache.depression_headache: got unexpected plan from when clause 1"
            with engine.prove('question', 'psych_symptom', context,
                              (rule.pattern(1),)) \
              as gen_2:
              for x_2 in gen_2:
                assert x_2 is None, \
                  "headache.depression_headache: got unexpected plan from when clause 2"
                rule.rule_base.num_bc_rule_successes += 1
                yield
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()

def temporal_arteritis(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(itertools.imap(lambda pat, arg:
                              pat.match_pattern(context, context,
                                                arg, arg_context),
                            patterns,
                            arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        with engine.prove('question', 'hd_symptom_aggravated', context,
                          (rule.pattern(0),)) \
          as gen_1:
          for x_1 in gen_1:
            assert x_1 is None, \
              "headache.temporal_arteritis: got unexpected plan from when clause 1"
            with engine.prove('question', 'labfinding', context,
                              (rule.pattern(1),)) \
              as gen_2:
              for x_2 in gen_2:
                assert x_2 is None, \
                  "headache.temporal_arteritis: got unexpected plan from when clause 2"
                rule.rule_base.num_bc_rule_successes += 1
                yield
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()

def favorable_answer(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(itertools.imap(lambda pat, arg:
                              pat.match_pattern(context, context,
                                                arg, arg_context),
                            patterns,
                            arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        with engine.prove('question', context.lookup_data('question'), context,
                          (rule.pattern(0),)) \
          as gen_1:
          for x_1 in gen_1:
            assert x_1 is None, \
              "headache.favorable_answer: got unexpected plan from when clause 1"
            with engine.prove('special', 'claim_goal', context,
                              ()) \
              as gen_2:
              for x_2 in gen_2:
                assert x_2 is None, \
                  "headache.favorable_answer: got unexpected plan from when clause 2"
                rule.rule_base.num_bc_rule_successes += 1
                yield
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()

def unfavorable_answer(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(itertools.imap(lambda pat, arg:
                              pat.match_pattern(context, context,
                                                arg, arg_context),
                            patterns,
                            arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        with engine.prove('question', context.lookup_data('question'), context,
                          (rule.pattern(0),)) \
          as gen_1:
          for x_1 in gen_1:
            assert x_1 is None, \
              "headache.unfavorable_answer: got unexpected plan from when clause 1"
            with engine.prove('special', 'claim_goal', context,
                              ()) \
              as gen_2:
              for x_2 in gen_2:
                assert x_2 is None, \
                  "headache.unfavorable_answer: got unexpected plan from when clause 2"
                rule.rule_base.num_bc_rule_successes += 1
                yield
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()

def unanswered(rule, arg_patterns, arg_context):
  engine = rule.rule_base.engine
  patterns = rule.goal_arg_patterns()
  if len(arg_patterns) == len(patterns):
    context = contexts.bc_context(rule)
    try:
      if all(itertools.imap(lambda pat, arg:
                              pat.match_pattern(context, context,
                                                arg, arg_context),
                            patterns,
                            arg_patterns)):
        rule.rule_base.num_bc_rules_matched += 1
        rule.rule_base.num_bc_rule_successes += 1
        yield
        rule.rule_base.num_bc_rule_failures += 1
    finally:
      context.done()

def populate(engine):
  This_rule_base = engine.get_create('headache')
  
  bc_rule.bc_rule('migraine', This_rule_base, 'diagnosis',
                  migraine, None,
                  (pattern.pattern_literal('migraine'),
                   contexts.variable('ans'),),
                  (),
                  (pattern.pattern_literal('hd_symptom_site'),
                   pattern.pattern_literal('unilateral'),
                   pattern.pattern_literal(0.8),
                   contexts.variable('ans1'),
                   pattern.pattern_literal('hd_symptom_type'),
                   pattern.pattern_literal('episodic'),
                   pattern.pattern_literal(0.4),
                   contexts.variable('ans2'),
                   pattern.pattern_literal('hd_symptom_character'),
                   pattern.pattern_literal('throbbing'),
                   contexts.variable('ans3'),
                   pattern.pattern_literal('hd_symptom_episode'),
                   pattern.pattern_literal('greater_than_2_hours'),
                   contexts.variable('ans4'),
                   pattern.pattern_literal('hd_symptom_lasts'),
                   pattern.pattern_literal('weeks'),
                   contexts.variable('ans5'),
                   contexts.variable('ans'),))
  
  bc_rule.bc_rule('classical_migraine', This_rule_base, 'diagnosis',
                  classical_migraine, None,
                  (pattern.pattern_literal('classical_migraine'),
                   pattern.pattern_tuple((contexts.variable('cf'), pattern.pattern_tuple((pattern.pattern_literal(('hd_symptom_aura', 1.0,)),), contexts.variable('questions')),), None),),
                  (),
                  (pattern.pattern_literal('migraine'),
                   pattern.pattern_tuple((contexts.variable('cf'), contexts.variable('questions'),), None),
                   pattern.pattern_literal(True),))
  
  bc_rule.bc_rule('opthalmoplegic_migraine', This_rule_base, 'diagnosis',
                  opthalmoplegic_migraine, None,
                  (pattern.pattern_literal('ophthalmoplegic_migraine'),
                   pattern.pattern_tuple((contexts.variable('cf'), pattern.pattern_tuple((pattern.pattern_literal(('hd_sign_cns', 1.0,)),), contexts.variable('questions')),), None),),
                  (),
                  (pattern.pattern_literal('migraine'),
                   pattern.pattern_tuple((contexts.variable('cf'), contexts.variable('questions'),), None),
                   pattern.pattern_literal('sixth_nerve'),))
  
  bc_rule.bc_rule('hemiplegic_migraine', This_rule_base, 'diagnosis',
                  hemiplegic_migraine, None,
                  (pattern.pattern_literal('hemiplegic_migraine'),
                   pattern.pattern_tuple((contexts.variable('cf'), pattern.pattern_tuple((pattern.pattern_literal(('hd_sign_cns', 1.0,)),), contexts.variable('questions')),), None),),
                  (),
                  (pattern.pattern_literal('migraine'),
                   pattern.pattern_tuple((contexts.variable('cf'), contexts.variable('questions'),), None),
                   pattern.pattern_literal('hemiparesis'),))
  
  bc_rule.bc_rule('basilar_migraine_1', This_rule_base, 'diagnosis',
                  basilar_migraine_1, None,
                  (pattern.pattern_literal('basilar_migraine'),
                   pattern.pattern_tuple((contexts.variable('cf'), pattern.pattern_tuple((pattern.pattern_literal(('vertigo', 1.0,)),), contexts.variable('questions')),), None),),
                  (),
                  (pattern.pattern_literal('migraine'),
                   pattern.pattern_tuple((contexts.variable('cf'), contexts.variable('questions'),), None),
                   pattern.pattern_literal(True),))
  
  bc_rule.bc_rule('basilar_migraine_2', This_rule_base, 'diagnosis',
                  basilar_migraine_2, None,
                  (pattern.pattern_literal('basilar_migraine'),
                   pattern.pattern_tuple((contexts.variable('cf'), pattern.pattern_tuple((pattern.pattern_literal(('ataxia', 1.0,)),), contexts.variable('questions')),), None),),
                  (),
                  (pattern.pattern_literal('migraine'),
                   pattern.pattern_tuple((contexts.variable('cf'), contexts.variable('questions'),), None),
                   pattern.pattern_literal(True),))
  
  bc_rule.bc_rule('cluster_headache_1', This_rule_base, 'diagnosis',
                  cluster_headache_1, None,
                  (pattern.pattern_literal('cluster_headache'),
                   contexts.variable('ans'),),
                  (),
                  (pattern.pattern_literal('hd_symptom_site'),
                   pattern.pattern_literal('bilateral'),
                   pattern.pattern_literal(8.0),
                   contexts.variable('ans1'),
                   pattern.pattern_literal('hd_symptom_type'),
                   pattern.pattern_literal('episodic'),
                   contexts.variable('ans2'),
                   pattern.pattern_literal('hd_symptom_location'),
                   pattern.pattern_literal('periorbital'),
                   contexts.variable('ans3'),
                   pattern.pattern_literal('hd_symptom_episode'),
                   pattern.pattern_literal('less_than_2_hours'),
                   pattern.pattern_literal(4.0),
                   contexts.variable('ans4'),
                   pattern.pattern_literal('hd_symptom_lasts'),
                   pattern.pattern_literal('less_than_4_days'),
                   pattern.pattern_literal(6.0),
                   contexts.variable('ans5'),
                   contexts.variable('ans'),))
  
  bc_rule.bc_rule('tension_headache', This_rule_base, 'diagnosis',
                  tension_headache, None,
                  (pattern.pattern_literal('tension_headache'),
                   contexts.variable('ans'),),
                  (),
                  (pattern.pattern_literal('hd_symptom_character'),
                   pattern.pattern_literal('bandlike'),
                   pattern.pattern_literal(9.0),
                   contexts.variable('ans1'),
                   pattern.pattern_literal('hd_symptom_diurnal'),
                   pattern.pattern_literal('evening'),
                   pattern.pattern_literal(6.0),
                   contexts.variable('ans2'),
                   contexts.variable('ans'),))
  
  bc_rule.bc_rule('depression_headache', This_rule_base, 'diagnosis',
                  depression_headache, None,
                  (pattern.pattern_literal('depression_headache'),
                   contexts.variable('ans'),),
                  (),
                  (pattern.pattern_literal('morning'),
                   pattern.pattern_literal('anhedonia'),))
  
  bc_rule.bc_rule('temporal_arteritis', This_rule_base, 'diagnosis',
                  temporal_arteritis, None,
                  (pattern.pattern_literal('temporal_arteritis'),
                   contexts.variable('ans'),),
                  (),
                  (pattern.pattern_literal('chewing'),
                   pattern.pattern_literal('raised_esr'),))
  
  bc_rule.bc_rule('favorable_answer', This_rule_base, 'score',
                  favorable_answer, None,
                  (contexts.variable('question'),
                   contexts.variable('ans'),
                   contexts.variable('max_score'),
                   pattern.pattern_tuple((contexts.variable('max_score'), contexts.variable('max_score'), pattern.pattern_literal(None),), None),),
                  (),
                  (contexts.variable('ans'),))
  
  bc_rule.bc_rule('unfavorable_answer', This_rule_base, 'score',
                  unfavorable_answer, None,
                  (contexts.variable('question'),
                   contexts.anonymous('_ans'),
                   contexts.variable('max_score'),
                   pattern.pattern_tuple((pattern.pattern_literal(0), contexts.variable('max_score'), pattern.pattern_literal(None),), None),),
                  (),
                  (contexts.anonymous('_bad_ans'),))
  
  bc_rule.bc_rule('unanswered', This_rule_base, 'score',
                  unanswered, None,
                  (contexts.variable('question'),
                   contexts.anonymous('_ans'),
                   contexts.variable('max_score'),
                   pattern.pattern_tuple((pattern.pattern_literal(0), contexts.variable('max_score'), contexts.variable('question'),), None),),
                  (),
                  ())

from naimath.engine.helpers import cf_threshold, sum_cf, mult_cf

Krb_filename = '../headache.krb'
Krb_lineno_map = (
    ((16, 20), (4, 4)),
    ((22, 30), (6, 6)),
    ((31, 39), (7, 7)),
    ((40, 48), (8, 8)),
    ((49, 57), (9, 9)),
    ((58, 66), (10, 10)),
    ((69, 69), (11, 11)),
    ((85, 89), (15, 16)),
    ((91, 97), (18, 18)),
    ((98, 103), (19, 19)),
    ((116, 120), (22, 23)),
    ((122, 128), (25, 25)),
    ((129, 134), (26, 26)),
    ((147, 151), (29, 29)),
    ((153, 159), (31, 31)),
    ((160, 165), (32, 32)),
    ((178, 182), (35, 35)),
    ((184, 190), (37, 37)),
    ((191, 196), (38, 38)),
    ((209, 213), (41, 41)),
    ((215, 221), (43, 43)),
    ((222, 227), (44, 44)),
    ((240, 244), (47, 47)),
    ((246, 254), (49, 49)),
    ((255, 263), (50, 50)),
    ((264, 272), (51, 51)),
    ((273, 281), (52, 52)),
    ((282, 290), (53, 53)),
    ((293, 293), (54, 54)),
    ((309, 313), (57, 57)),
    ((315, 323), (59, 59)),
    ((324, 332), (60, 60)),
    ((335, 335), (61, 61)),
    ((351, 355), (64, 64)),
    ((357, 362), (66, 66)),
    ((363, 368), (67, 67)),
    ((381, 385), (70, 70)),
    ((387, 392), (72, 72)),
    ((393, 398), (73, 73)),
    ((411, 415), (76, 76)),
    ((417, 422), (78, 78)),
    ((423, 428), (79, 79)),
    ((441, 445), (82, 82)),
    ((447, 452), (84, 84)),
    ((453, 458), (85, 85)),
    ((471, 475), (88, 88)),
)
